﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Sprite
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Represents a Sprite object for use in 2D gameplay.</para>
  /// </summary>
  [NativeType("Runtime/Graphics/SpriteFrame.h")]
  [NativeHeader("Runtime/2D/Common/ScriptBindings/SpritesMarshalling.h")]
  [NativeHeader("Runtime/2D/Common/SpriteDataAccess.h")]
  [ExcludeFromPreset]
  [NativeHeader("Runtime/Graphics/SpriteUtility.h")]
  public sealed class Sprite : Object
  {
    [RequiredByNativeCode]
    private Sprite()
    {
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern int GetPackingMode();

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern int GetPackingRotation();

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern int GetPacked();

    internal Rect GetTextureRect()
    {
      Rect ret;
      this.GetTextureRect_Injected(out ret);
      return ret;
    }

    internal Vector2 GetTextureRectOffset()
    {
      Vector2 ret;
      this.GetTextureRectOffset_Injected(out ret);
      return ret;
    }

    internal Vector4 GetInnerUVs()
    {
      Vector4 ret;
      this.GetInnerUVs_Injected(out ret);
      return ret;
    }

    internal Vector4 GetOuterUVs()
    {
      Vector4 ret;
      this.GetOuterUVs_Injected(out ret);
      return ret;
    }

    internal Vector4 GetPadding()
    {
      Vector4 ret;
      this.GetPadding_Injected(out ret);
      return ret;
    }

    [FreeFunction("SpritesBindings::CreateSpriteWithoutTextureScripting")]
    internal static Sprite CreateSpriteWithoutTextureScripting(
      Rect rect,
      Vector2 pivot,
      float pixelsToUnits,
      Texture2D texture)
    {
      return Sprite.CreateSpriteWithoutTextureScripting_Injected(ref rect, ref pivot, pixelsToUnits, texture);
    }

    [FreeFunction("SpritesBindings::CreateSprite")]
    internal static Sprite CreateSprite(
      Texture2D texture,
      Rect rect,
      Vector2 pivot,
      float pixelsPerUnit,
      uint extrude,
      SpriteMeshType meshType,
      Vector4 border,
      bool generateFallbackPhysicsShape)
    {
      return Sprite.CreateSprite_Injected(texture, ref rect, ref pivot, pixelsPerUnit, extrude, meshType, ref border, generateFallbackPhysicsShape);
    }

    /// <summary>
    ///   <para>Bounds of the Sprite, specified by its center and extents in world space units.</para>
    /// </summary>
    public Bounds bounds
    {
      get
      {
        Bounds ret;
        this.get_bounds_Injected(out ret);
        return ret;
      }
    }

    /// <summary>
    ///   <para>Location of the Sprite on the original Texture, specified in pixels.</para>
    /// </summary>
    public Rect rect
    {
      get
      {
        Rect ret;
        this.get_rect_Injected(out ret);
        return ret;
      }
    }

    /// <summary>
    ///   <para>Returns the border sizes of the sprite.</para>
    /// </summary>
    public Vector4 border
    {
      get
      {
        Vector4 ret;
        this.get_border_Injected(out ret);
        return ret;
      }
    }

    /// <summary>
    ///   <para>Get the reference to the used texture. If packed this will point to the atlas, if not packed will point to the source sprite.</para>
    /// </summary>
    public extern Texture2D texture { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern Texture2D GetSecondaryTexture(int index);

    /// <summary>
    ///   <para>The number of pixels in the sprite that correspond to one unit in world space. (Read Only)</para>
    /// </summary>
    public extern float pixelsPerUnit { [NativeMethod("GetPixelsToUnits"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The Variant scale of texture used by the Sprite. This is useful to check when a Variant SpriteAtlas is being used by Sprites.</para>
    /// </summary>
    public extern float spriteAtlasTextureScale { [NativeMethod("GetSpriteAtlasTextureScale"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///         <para>Returns the texture that contains the alpha channel from the source texture. Unity generates this texture under the hood for sprites that have alpha in the source, and need to be compressed using techniques like ETC1.
    /// 
    /// Returns NULL if there is no associated alpha texture for the source sprite. This is the case if the sprite has not been setup to use ETC1 compression.</para>
    ///       </summary>
    public extern Texture2D associatedAlphaSplitTexture { [NativeMethod("GetAlphaTexture"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Location of the Sprite's pivot point in the Rect on the original Texture, specified in pixels.</para>
    /// </summary>
    public Vector2 pivot
    {
      [NativeMethod("GetPivotInPixels")] get
      {
        Vector2 ret;
        this.get_pivot_Injected(out ret);
        return ret;
      }
    }

    public extern bool isUsingPlaceholder { [NativeMethod("IsUsingPlaceholder"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Returns true if this Sprite is packed in an atlas.</para>
    /// </summary>
    public bool packed => this.GetPacked() == 1;

    /// <summary>
    ///   <para>If Sprite is packed (see Sprite.packed), returns its SpritePackingMode.</para>
    /// </summary>
    public SpritePackingMode packingMode => (SpritePackingMode) this.GetPackingMode();

    /// <summary>
    ///   <para>If Sprite is packed (see Sprite.packed), returns its SpritePackingRotation.</para>
    /// </summary>
    public SpritePackingRotation packingRotation
    {
      get => (SpritePackingRotation) this.GetPackingRotation();
    }

    /// <summary>
    ///   <para>Get the rectangle this sprite uses on its texture. Raises an exception if this sprite is tightly packed in an atlas.</para>
    /// </summary>
    public Rect textureRect
    {
      get
      {
        return this.packed && this.packingMode != SpritePackingMode.Rectangle ? Rect.zero : this.GetTextureRect();
      }
    }

    /// <summary>
    ///   <para>Gets the offset of the rectangle this sprite uses on its texture to the original sprite bounds. If sprite mesh type is FullRect, offset is zero.</para>
    /// </summary>
    public Vector2 textureRectOffset
    {
      get
      {
        return this.packed && this.packingMode != SpritePackingMode.Rectangle ? Vector2.zero : this.GetTextureRectOffset();
      }
    }

    /// <summary>
    ///   <para>Returns a copy of the array containing sprite mesh vertex positions.</para>
    /// </summary>
    public extern Vector2[] vertices { [FreeFunction("SpriteAccessLegacy::GetSpriteVertices", HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Returns a copy of the array containing sprite mesh triangles.</para>
    /// </summary>
    public extern ushort[] triangles { [FreeFunction("SpriteAccessLegacy::GetSpriteIndices", HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The base texture coordinates of the sprite mesh.</para>
    /// </summary>
    public extern Vector2[] uv { [FreeFunction("SpriteAccessLegacy::GetSpriteUVs", HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The number of physics shapes for the Sprite.</para>
    /// </summary>
    /// <returns>
    ///   <para>The number of physics shapes for the Sprite.</para>
    /// </returns>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern int GetPhysicsShapeCount();

    /// <summary>
    ///   <para>The number of points in the selected physics shape for the Sprite.</para>
    /// </summary>
    /// <param name="shapeIdx">The index of the physics shape to retrieve the number of points from.</param>
    /// <returns>
    ///   <para>The number of points in the selected physics shape for the Sprite.</para>
    /// </returns>
    public int GetPhysicsShapePointCount(int shapeIdx)
    {
      int physicsShapeCount = this.GetPhysicsShapeCount();
      return shapeIdx >= 0 && shapeIdx < physicsShapeCount ? this.Internal_GetPhysicsShapePointCount(shapeIdx) : throw new IndexOutOfRangeException(string.Format("Index({0}) is out of bounds(0 - {1})", (object) shapeIdx, (object) (physicsShapeCount - 1)));
    }

    [NativeMethod("GetPhysicsShapePointCount")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern int Internal_GetPhysicsShapePointCount(int shapeIdx);

    public int GetPhysicsShape(int shapeIdx, List<Vector2> physicsShape)
    {
      int physicsShapeCount = this.GetPhysicsShapeCount();
      if (shapeIdx < 0 || shapeIdx >= physicsShapeCount)
        throw new IndexOutOfRangeException(string.Format("Index({0}) is out of bounds(0 - {1})", (object) shapeIdx, (object) (physicsShapeCount - 1)));
      Sprite.GetPhysicsShapeImpl(this, shapeIdx, physicsShape);
      return physicsShape.Count;
    }

    [FreeFunction("SpritesBindings::GetPhysicsShape", ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetPhysicsShapeImpl(
      Sprite sprite,
      int shapeIdx,
      [NotNull("ArgumentNullException")] List<Vector2> physicsShape);

    public void OverridePhysicsShape(IList<Vector2[]> physicsShapes)
    {
      if (physicsShapes == null)
        throw new ArgumentNullException(nameof (physicsShapes));
      for (int index = 0; index < physicsShapes.Count; ++index)
      {
        Vector2[] physicsShape = physicsShapes[index];
        if (physicsShape == null)
          throw new ArgumentNullException("physicsShape", string.Format("Physics Shape at {0} is null.", (object) index));
        if (physicsShape.Length < 3)
          throw new ArgumentException(string.Format("Physics Shape at {0} has less than 3 vertices ({1}).", (object) index, (object) physicsShape.Length));
      }
      Sprite.OverridePhysicsShapeCount(this, physicsShapes.Count);
      for (int index = 0; index < physicsShapes.Count; ++index)
        Sprite.OverridePhysicsShape(this, physicsShapes[index], index);
    }

    [FreeFunction("SpritesBindings::OverridePhysicsShapeCount")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void OverridePhysicsShapeCount(Sprite sprite, int physicsShapeCount);

    [FreeFunction("SpritesBindings::OverridePhysicsShape", ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void OverridePhysicsShape(Sprite sprite, [Unmarshalled] Vector2[] physicsShape, int idx);

    /// <summary>
    ///   <para>Sets up new Sprite geometry.</para>
    /// </summary>
    /// <param name="vertices">Array of vertex positions in Sprite Rect space.</param>
    /// <param name="triangles">Array of sprite mesh triangle indices.</param>
    [FreeFunction("SpritesBindings::OverrideGeometry", HasExplicitThis = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void OverrideGeometry([Unmarshalled, NotNull("ArgumentNullException")] Vector2[] vertices, [Unmarshalled, NotNull("ArgumentNullException")] ushort[] triangles);

    internal static Sprite Create(
      Rect rect,
      Vector2 pivot,
      float pixelsToUnits,
      Texture2D texture)
    {
      return Sprite.CreateSpriteWithoutTextureScripting(rect, pivot, pixelsToUnits, texture);
    }

    internal static Sprite Create(Rect rect, Vector2 pivot, float pixelsToUnits)
    {
      return Sprite.CreateSpriteWithoutTextureScripting(rect, pivot, pixelsToUnits, (Texture2D) null);
    }

    /// <summary>
    ///   <para>Create a new Sprite object.</para>
    /// </summary>
    /// <param name="texture">Texture from which to obtain the sprite graphic.</param>
    /// <param name="rect">Rectangular section of the texture to use for the sprite.</param>
    /// <param name="pivot">Sprite's pivot point relative to its graphic rectangle.</param>
    /// <param name="pixelsPerUnit">The number of pixels in the sprite that correspond to one unit in world space.</param>
    /// <param name="extrude">Amount by which the sprite mesh should be expanded outwards.</param>
    /// <param name="meshType">Controls the type of mesh generated for the sprite.</param>
    /// <param name="border">The border sizes of the sprite (X=left, Y=bottom, Z=right, W=top).</param>
    /// <param name="generateFallbackPhysicsShape">Generates a default physics shape for the sprite.</param>
    public static Sprite Create(
      Texture2D texture,
      Rect rect,
      Vector2 pivot,
      float pixelsPerUnit,
      uint extrude,
      SpriteMeshType meshType,
      Vector4 border,
      bool generateFallbackPhysicsShape)
    {
      if ((Object) texture == (Object) null)
        return (Sprite) null;
      if ((double) rect.xMax > (double) texture.width || (double) rect.yMax > (double) texture.height)
        throw new ArgumentException(string.Format("Could not create sprite ({0}, {1}, {2}, {3}) from a {4}x{5} texture.", (object) rect.x, (object) rect.y, (object) rect.width, (object) rect.height, (object) texture.width, (object) texture.height));
      if ((double) pixelsPerUnit <= 0.0)
        throw new ArgumentException("pixelsPerUnit must be set to a positive non-zero value.");
      return Sprite.CreateSprite(texture, rect, pivot, pixelsPerUnit, extrude, meshType, border, generateFallbackPhysicsShape);
    }

    /// <summary>
    ///   <para>Create a new Sprite object.</para>
    /// </summary>
    /// <param name="texture">Texture from which to obtain the sprite graphic.</param>
    /// <param name="rect">Rectangular section of the texture to use for the sprite.</param>
    /// <param name="pivot">Sprite's pivot point relative to its graphic rectangle.</param>
    /// <param name="pixelsPerUnit">The number of pixels in the sprite that correspond to one unit in world space.</param>
    /// <param name="extrude">Amount by which the sprite mesh should be expanded outwards.</param>
    /// <param name="meshType">Controls the type of mesh generated for the sprite.</param>
    /// <param name="border">The border sizes of the sprite (X=left, Y=bottom, Z=right, W=top).</param>
    /// <param name="generateFallbackPhysicsShape">Generates a default physics shape for the sprite.</param>
    public static Sprite Create(
      Texture2D texture,
      Rect rect,
      Vector2 pivot,
      float pixelsPerUnit,
      uint extrude,
      SpriteMeshType meshType,
      Vector4 border)
    {
      return Sprite.Create(texture, rect, pivot, pixelsPerUnit, extrude, meshType, border, false);
    }

    /// <summary>
    ///   <para>Create a new Sprite object.</para>
    /// </summary>
    /// <param name="texture">Texture from which to obtain the sprite graphic.</param>
    /// <param name="rect">Rectangular section of the texture to use for the sprite.</param>
    /// <param name="pivot">Sprite's pivot point relative to its graphic rectangle.</param>
    /// <param name="pixelsPerUnit">The number of pixels in the sprite that correspond to one unit in world space.</param>
    /// <param name="extrude">Amount by which the sprite mesh should be expanded outwards.</param>
    /// <param name="meshType">Controls the type of mesh generated for the sprite.</param>
    /// <param name="border">The border sizes of the sprite (X=left, Y=bottom, Z=right, W=top).</param>
    /// <param name="generateFallbackPhysicsShape">Generates a default physics shape for the sprite.</param>
    public static Sprite Create(
      Texture2D texture,
      Rect rect,
      Vector2 pivot,
      float pixelsPerUnit,
      uint extrude,
      SpriteMeshType meshType)
    {
      return Sprite.Create(texture, rect, pivot, pixelsPerUnit, extrude, meshType, Vector4.zero);
    }

    /// <summary>
    ///   <para>Create a new Sprite object.</para>
    /// </summary>
    /// <param name="texture">Texture from which to obtain the sprite graphic.</param>
    /// <param name="rect">Rectangular section of the texture to use for the sprite.</param>
    /// <param name="pivot">Sprite's pivot point relative to its graphic rectangle.</param>
    /// <param name="pixelsPerUnit">The number of pixels in the sprite that correspond to one unit in world space.</param>
    /// <param name="extrude">Amount by which the sprite mesh should be expanded outwards.</param>
    /// <param name="meshType">Controls the type of mesh generated for the sprite.</param>
    /// <param name="border">The border sizes of the sprite (X=left, Y=bottom, Z=right, W=top).</param>
    /// <param name="generateFallbackPhysicsShape">Generates a default physics shape for the sprite.</param>
    public static Sprite Create(
      Texture2D texture,
      Rect rect,
      Vector2 pivot,
      float pixelsPerUnit,
      uint extrude)
    {
      return Sprite.Create(texture, rect, pivot, pixelsPerUnit, extrude, SpriteMeshType.Tight);
    }

    /// <summary>
    ///   <para>Create a new Sprite object.</para>
    /// </summary>
    /// <param name="texture">Texture from which to obtain the sprite graphic.</param>
    /// <param name="rect">Rectangular section of the texture to use for the sprite.</param>
    /// <param name="pivot">Sprite's pivot point relative to its graphic rectangle.</param>
    /// <param name="pixelsPerUnit">The number of pixels in the sprite that correspond to one unit in world space.</param>
    /// <param name="extrude">Amount by which the sprite mesh should be expanded outwards.</param>
    /// <param name="meshType">Controls the type of mesh generated for the sprite.</param>
    /// <param name="border">The border sizes of the sprite (X=left, Y=bottom, Z=right, W=top).</param>
    /// <param name="generateFallbackPhysicsShape">Generates a default physics shape for the sprite.</param>
    public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit)
    {
      return Sprite.Create(texture, rect, pivot, pixelsPerUnit, 0U);
    }

    /// <summary>
    ///   <para>Create a new Sprite object.</para>
    /// </summary>
    /// <param name="texture">Texture from which to obtain the sprite graphic.</param>
    /// <param name="rect">Rectangular section of the texture to use for the sprite.</param>
    /// <param name="pivot">Sprite's pivot point relative to its graphic rectangle.</param>
    /// <param name="pixelsPerUnit">The number of pixels in the sprite that correspond to one unit in world space.</param>
    /// <param name="extrude">Amount by which the sprite mesh should be expanded outwards.</param>
    /// <param name="meshType">Controls the type of mesh generated for the sprite.</param>
    /// <param name="border">The border sizes of the sprite (X=left, Y=bottom, Z=right, W=top).</param>
    /// <param name="generateFallbackPhysicsShape">Generates a default physics shape for the sprite.</param>
    public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot)
    {
      return Sprite.Create(texture, rect, pivot, 100f);
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetTextureRect_Injected(out Rect ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetTextureRectOffset_Injected(out Vector2 ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetInnerUVs_Injected(out Vector4 ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetOuterUVs_Injected(out Vector4 ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetPadding_Injected(out Vector4 ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern Sprite CreateSpriteWithoutTextureScripting_Injected(
      ref Rect rect,
      ref Vector2 pivot,
      float pixelsToUnits,
      Texture2D texture);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern Sprite CreateSprite_Injected(
      Texture2D texture,
      ref Rect rect,
      ref Vector2 pivot,
      float pixelsPerUnit,
      uint extrude,
      SpriteMeshType meshType,
      ref Vector4 border,
      bool generateFallbackPhysicsShape);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_bounds_Injected(out Bounds ret);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_rect_Injected(out Rect ret);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_border_Injected(out Vector4 ret);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_pivot_Injected(out Vector2 ret);
  }
}
